<template>
  <div>
    <form action="javascript:;" class="editPublish-blink-form">
      <div  class="textArea">
            <textarea resize="none"
                      placeholder="请编写【500】字以内的文本..."
                      v-model="blinkInfo.blinkContent"
            ></textarea>
        <input type="submit" value="发布" class="publish-tip" @click="publishBlink"></input>
      </div>
    </form>
  </div>
</template>

<script>
    export default {
        name: "PublishPage-blink",
        data() {
            return {
                blinkInfo:{
                    blinkContent:'',
                    blinkId:'',
                },
                baseURL:'http://localhost:8081/publishPage/blink/',
                baseURL2:'http://localhost:8081/publishPage/editBlink/',
            };
        },
        mounted(){
            this.$emit("component","blink")
            this.getBlinkInfo()
        },
        methods:{
            getBlinkInfo(){
                let workId = this.$route.query.workId
                if (typeof workId != "undefined"){
                    this.blinkInfo.blinkId = workId
                    this.axios.post(this.baseURL2+workId).then(res=>{
                        if (res.data != false){
                            this.blinkInfo.blinkContent = res.data
                        } else {
                            this.$message.error("服务器异常，内容加载失败")
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },
            publishBlink(){
                this.$confirm('确认进行发布/更新操作?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    showClose: false,
                    type: 'warning'
                }).then(() => {
                    if (this.blinkInfo.blinkContent.length>500){
                        this.$message("【纯文本】字数超过了【500】")
                    } else if (this.blinkInfo.blinkContent == ''){
                        this.$message("请编写【Blink】")
                    } else {
                        let configs = {
                            headers:{ 'Content-Type':'application/json'}  // 设置说明上传JSON
                        };
                        this.axios.post(this.baseURL, this.blinkInfo, configs).then(res=>{
                            if (res.data ==true) {
                                if (this.blinkInfo.blinkId ==""){
                                    this.successOpt("Blink发布成功")
                                } else {
                                    this.successOpt("Blink更新成功")
                                }
                                this.blinkInfo.blinkContent = ''
                                this.blinkInfo.id = ''
                            } else if (res.date == false){
                                this.failOpt("Blink发布失败")
                            }
                        }).catch(
                            exception=>{
                                console.log(exception)
                            }
                        )
                    }
                }).catch(() => {
                    console.log('已取消删除')
                });
            },
            successOpt(message) {
                this.$notify({
                    title: '成功',
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: '错误',
                    message: message
                });
            },
            warningOpt() {
                this.$notify.warning({
                    title: '提示',
                    message: '服务器异常，勿重复尝试'
                });
            },
        }
    }
</script>

<style scoped>

  .editPublish-blink-form{
    width: 100%;
  }


  .textArea{
    width: 100%;
    margin: 0 auto;
  }
  .textArea textarea{
    height: 400px;
    width: 96.3%;
    /*不允许用户调整元素大小*/
    resize:none;
    font-size: 15px;
    border: #ffffff 1px solid;
    border-radius: 3px;
    padding: 20px 20px;
    box-shadow: 0 0 10px #dadada;
    color: #333333;
    letter-spacing: 1.5px;
    font-size: 15px;
  }
  .textArea textarea::placeholder{
    color: #bdc6d0;
    font-size: 14px;
  }
  .publish-tip{
    width: 100%;
    height: 30px;
    line-height: 30px;
    font-size: 13px;
    text-align: center;
    letter-spacing: 2px;
    border-radius: 3px;
    color: rgb(191, 191, 191);
    background-color: white;
    margin-top: 10px;
    border: 1px solid  transparent;
    font-weight: bolder;
    box-shadow: 0 0 10px #d2d2d2;
    transition: 0.2s;
  }
  .publish-tip:hover{
    color: rgb(113, 113, 113);
    /*background-color: #6c6c6c;*/
    /*border: 1px solid #888689;*/
    border: 1px dashed #c7c5c8;
  }
  .publish-tip:active{
    border: 1px dashed #000000;
  }
  .publish-tip{
     width: 100%;
     height: 30px;
     line-height: 30px;
     font-size: 13px;
     text-align: center;
     letter-spacing: 2px;
     border-radius: 3px;
     color: rgb(191, 191, 191);
     background-color: white;
     margin-top: 10px;
     border: 1px solid  transparent;
     font-weight: bolder;
     box-shadow: 0 0 10px #d2d2d2;
     transition: 0.2s;
   }
  .publish-tip:hover{
    color: rgb(113, 113, 113);
    /*background-color: #6c6c6c;*/
    /*border: 1px solid #888689;*/
    border: 1px dashed #c7c5c8;
  }
  .publish-tip:active{
    border: 1px dashed #000000;
  }
  .editPublish-blink-form{
    width: 100%;
  }


  /*.textArea{*/
  /*  width: 100%;*/
  /*  margin: 0 auto;*/
  /*}*/
  /*.textArea textarea{*/
  /*  height: 150px;*/
  /*  width: 96.3%;*/
  /*  resize:none;  */
  /* font-size: 15px;*/
  /*  border: #ffffff 1px solid;*/
  /*  border-radius: 3px;*/
  /*  padding: 20px 20px;*/
  /*  box-shadow: 0 0 10px #dadada;*/
  /*  color: #333333;*/
  /*  letter-spacing: 1.5px;*/
  /*  font-size: 15px;*/
  /*}*/
  /*.textArea textarea::placeholder{*/
  /*  color: #bdc6d0;*/
  /*  font-size: 14px;*/
  /*}*/
</style>
